<script>

/**
 * Orders Component
 */
export default {
  data() {
    return {
      ordersData: [
        {
          name: "锦创科技股份有限公司",
          source: "313",
          weMedia: "2,542",
          callInterface: "31",
          industry: "金融",
          joinTime: "2017/5/17",
          currentState: "合作中"
        },{
          name: "工商银行南京分行",
          source: "674",
          weMedia: "4321",
          callInterface: "24",
          industry: "金融",
          joinTime: "2017/6/22",
          currentState: "合作中"
        },{
          name: "光大证券上海公司",
          source: "3,241",
          weMedia: "321",
          callInterface: "55",
          industry: "金融",
          joinTime: "2018/5/17",
          currentState: "合作中"
        },{
          name: "江苏省公安厅",
          source: "12,386",
          weMedia: "1,241",
          callInterface: "125",
          industry: "政府",
          joinTime: "2018/7/12",
          currentState: "合作中"
        },{
          name: "江苏百瑞赢投顾",
          source: "3,214",
          weMedia: "8,761",
          callInterface: "241",
          industry: "金融",
          joinTime: "2019/5/7",
          currentState: "合作中"
        },{
          name: "东南大学",
          source: "209",
          weMedia: "125",
          callInterface: "130",
          industry: "教育",
          joinTime: "2020/11/24",
          currentState: "合作中"
        },{
          name: "南瑞集团",
          source: "302",
          weMedia: "223",
          callInterface: "137",
          industry: "电力",
          joinTime: "2020/5/17",
          currentState: "合作中"
        },{
          name: "南京企运网",
          source: "3,214",
          weMedia: "331",
          callInterface: "211",
          industry: "服务",
          joinTime: "2020/6/22",
          currentState: "合作中"
        },{
          name: "上海虑远",
          source: "3,153",
          weMedia: "322",
          callInterface: "201",
          industry: '金融',
          joinTime: "2020/7/12",
          currentState: "合作中"
        },{
          name: "合肥人行",
          source: "2,178",
          weMedia: "252",
          callInterface: "188",
          industry: '金融',
          joinTime: "2020/7/25",
          currentState: "合作中"
        },{
          name: "铜陵人行",
          source: "2,148",
          weMedia: "245",
          callInterface: "190",
          industry: '金融',
          joinTime: "2020/8/06",
          currentState: "合作中"
        },{
          name: "中国联通",
          source: "5,531",
          weMedia: "3,210",
          callInterface: "132",
          industry: "运营商",
          joinTime: "2020/8/17",
          currentState: "合作中"
        },{
          name: "国家电网",
          source: "6,687",
          weMedia: "3,210",
          callInterface: "324",
          industry: "电力",
          joinTime: "2020/9/19",
          currentState: "合作中"
        }
      ],
      totalRows: 100,
      currentPage: 1,
      perPage: 10,
      fields: [
        { key: "name", label: "客户单位" },
        { key: "source", label: "涉及信源" },
        { key: "weMedia", label: "自媒体号" },
        { key: "callInterface", label: "调用接口" },
        { key: "industry", label: "客户行业" },
        { key: "joinTime", label: "加入时间" },
        { key: "currentState", label: "当前状态" },
      ],
    };
  },
  watch: {
    "currentPage": {
      handler(){
        console.log("触发更新");
      }
    }
  },
  methods: {
    /**
     * Search the table data with search input
     */
    onFiltered(filteredItems) {
      // Trigger pagination to update the number of buttons/pages due to filtering
      this.totalRows = filteredItems.length;
      this.currentPage = 1;
    },
    toDetail(){
      this.$router.push('/custom/detail')
      // let routeUrl = this.$router.resolve({
      //   path: '/custom/detail'
      // });
      // window.open(routeUrl.href, '_blank');
    },
    Search(){
      alert(this.searchinp)
    },
    addCustomer(){
      this.$router.push('/custom/detail')
    },
  }
};
</script>

<template>
  <div>
    <!-- 搜索 -->
    <div class="search-box">
      <div class="position-relative search">
        <input type="text" @keyup.enter="Search" class="form-control" placeholder="请输入关键字" />
        <i class="mdi mdi-magnify search-icon"></i>
      </div>
    </div>
    <div class="allNum">
      <div class="searchNum">为您检索到<span>5,000+</span>条信息</div>
      <div>
        <b-button @click="addCustomer" pill variant="dark">
          <i class="ri-add-line align-middle" style="font-size: 1rem;margin-right:6px;"></i>添加客户
        </b-button>
      </div>
    </div>
    <div class="table-responsive">
      <b-table
        class="table-centered"
        :items="ordersData"
        :fields="fields"
        responsive="sm"
        :per-page="perPage"
        :current-page="1"
        thead-class="thead-light"
        @filtered="onFiltered"
      >
        <template v-slot:cell(name)="row">
          <a style="color: #5664d2;" @click="toDetail(row.item)" target="_blank">{{row.value}}</a>
        </template>
        <template v-slot:cell(currentState)="row">
          <div v-if="row.value=='合作中'" class="badge font-size-12 badge-soft-success">{{row.value}}</div>
          <div v-else class="badge font-size-12 badge-soft-danger">{{row.value}}</div>
        </template>
      </b-table>
    </div>
    <div class="row">
      <div class="col">
        <div class="dataTables_paginate paging_simple_numbers float-right">
          <ul class="pagination pagination-rounded mb-0">
            <!-- pagination -->
            <b-pagination v-model="currentPage" :total-rows="totalRows" :per-page="perPage"></b-pagination>
          </ul>
        </div>
      </div>
    </div>
  </div>
</template>
<style lang="scss" scoped>
.search {
  // float: left;
  width: 300px;
}
.allNum{
  padding: 20px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.searchNum{
  span{
    font-size: 1rem;
    color: #3444c1;
    margin: 0 4px;
    font-weight: 600;
  }
}
.table-centered{
  ::v-deep thead,::v-deep tbody{
    tr{
      th:last-child,td:last-child{
        text-align: right;
      }
    }
  }
}
</style>

